import 'package:freedom/page/mahjong/common/mahjong_context.dart';
import 'package:freedom/page/mahjong/common/message_content.dart';
import 'package:freedom/page/mahjong/event/user_swap_event.dart';
import 'package:freedom/page/mahjong/message/abstract_action_message.dart';

class ExchangeAction extends AbstractMessageActionHandler<MahjongMessage> {
  @override
  void doMessage(MahjongMessage message) {
    var userDiskInfo = MahjongContext.getUserStateById(message.exeActionUid);
    if (userDiskInfo == null) {
      return;
    }
    MahjongContext.postUserEvent<UserSwapEvent>(
        message.exeActionUid, UserSwapEvent(message.swapCard, SwapState.OUT));
    MahjongContext.mahjongGameIndex.swapCardAction
        ?.swapCard(userDiskInfo.direction, swapCard: message.swapCard);
    // 这里有可能收到别人发出的信息,自己收到的信息是有换牌信息的
    if (message.swapCard?.isNotEmpty ?? false) {
      MahjongContext().updateSwapCardOut(message.swapCard!.join(","));
    }
  }
}
